﻿using System.Collections.Generic;

namespace Jayden.Dll.Core.Translations
{
	public class DictionaryTranslator : Dictionary<string, string>, ITranslator
	{
		private string m_SourceLang;
		private string m_Lang;

		public DictionaryTranslator(string lang) : this(string.Empty, lang) { }
		public DictionaryTranslator(string source, string lang)
		{
			m_SourceLang = source;
			m_Lang = lang;
		}

		public string SourceLang { get { return m_SourceLang; } }

		public string Lang { get { return m_Lang; } }

		public string Translate(string source)
		{
			if (string.IsNullOrWhiteSpace(source))
				return source;
			string translation = null;
			if (TryGetValue(source, out translation))
			{
				if (translation == null)
					return source;
				return translation;
			}
			Add(source, null);
			return source;
		}

		public string Translate(string source, params object[] args) { return string.Format(Translate(source), args); }
	}
}
